package platform.wx.util;

import com.alibaba.fastjson.JSON;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
import platform.wx.domain.ServerMsgProtocol;

public class MsgUtil {
    public static TextWebSocketFrame buildMsgAll(String channelId, String msgInfo) {
        // 模拟头像
        int i =  Math.abs(channelId.hashCode()) % 10;
        ServerMsgProtocol msg = new ServerMsgProtocol();
        msg.setMsgInfo(msgInfo);
        msg.setType(2);//1自发  2：群发消息
        msg.setChannelId(channelId);
        msg.setUserHeadImg("head"+i+"jpg");

        return new TextWebSocketFrame(JSON.toJSONString(msg));
    }

    public static TextWebSocketFrame buildMsgOwner(String channelId){
        ServerMsgProtocol msgProtocol = new ServerMsgProtocol();
        msgProtocol.setType(1);
        msgProtocol.setChannelId(channelId);
        return  new TextWebSocketFrame(JSON.toJSONString(msgProtocol));
    }
}
